using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using Helpers;
using Common.Constants;
using System.Drawing;


namespace HttpRequester.RequestMakers.Base
{
    public class RequestManagerImage : RequestManagerBase
    {
        public RequestManagerImage()
            : base()
        {
            Method = HttpMethod.GET;
        }

        public Image Image { get; set; }

        public override void ProcessResponse(HttpWebResponse response)
        {
            Image = ReadResponseContent(response);
        }

        protected Image ReadResponseContent(HttpWebResponse response)
        {
            Image result = null;
            Stream strm = null;
            try
            {
                strm = response.GetResponseStream();
                result = Image.FromStream(strm);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error(ex.Message);
            }
            finally
            {
                if (strm != null)
                    strm.Close();
            }

            return result;
        }

        public override void SaveResponseContent(string fileName)
        {
            try
            {
                Image.Save(fileName);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error(ex.Message);
            }
        }
    }
}
